/**
 * @param {number} n
 * @return {boolean}
 */
function getSum (n) {
    let sum = 0;
    while(n) {
        let g = n % 10;
        n =  Math.floor(n/10)       //js中19/10是1.9，不是整除，需要进行处理
        sum += g*g;
    }
    return sum;
}
var isHappy = function(n) {
    let set = new Set();
    while(true) {
        let num = getSum(n);
        if(set.has(num)) {
            return false;
        }else if(num!=1){
            set.add(num);
            n = num;
        }else {
            return true
        }
    }
};
console.log(isHappy(19))